/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// Package main implements a client for Greeter service.
package main

import (
	"context"
	"flag"
	"log"
	"time"

	pb "gitee.com/rs1314/taiqiu/proto/dao"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

var (
	addr    = flag.String("addr", "localhost:60001", "the address to connect to")
	appId   = flag.String("appId", "1234", "userId to set")
	openId  = flag.String("openId", "qwenyang", "nickName to set")
	unionId = flag.String("avatarUrl", "unionId", "avatarUrl to set")
)

func main() {
	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewXMetauDaoServiceClient(conn)

	// Contact the server and print out its response.
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	login := &pb.Login{
		LoginType: 0,
		AppId:     *appId,
		OpenId:    *openId,
		UnionId:   *unionId,
	}

	req := &pb.LoginReq{
		Login: login,
	}
	r, err := c.Login(ctx, req)
	if err != nil {
		log.Fatalf("query user failed: %v", err)
	}
	log.Printf("login ok %v", r)
}
